package Dao.Impl;

import Bean.Order;
import Bean.OrderItem;
import Dao.BasicDao;
import Dao.OrderDao;

import java.util.ArrayList;
import java.util.List;

public class OrderDaoImpl extends BasicDao implements OrderDao {
    @Override
    public void insertOrder(Order order) {
        String sql = "insert into Orders(orderNumber,userId, sumPrice) values (?,?,?)";
        dml(sql,order.getOrderNumber(),order.getUserId(),order.getSumPrice());
    }

    @Override
    public List<Order> getALLOrder(Integer userId) {
        List<Order> orders = new ArrayList<>();
        String sql ="select ORDERNUMBER, DATETIME, USERID, SUMPRICE, STATUE from Orders  where userId=?;";
        orders = getSomeQuery(sql, Order.class, userId);
        return orders;
    }

    @Override
    public void insertOrderItem(OrderItem orderItem) {
        String sql = "insert into OrdersItem(orderNumber, furnName, price, amount, sumPrice) VALUES (?,?,?,?,?);";
        dml(sql,orderItem.getOrderNumber(),orderItem.getFurnName(),orderItem.getPrice(),orderItem.getAmount(),orderItem.getSumPrice());
    }

    @Override
    public List<OrderItem> getOrderALL(String orderNumber) {
        String sqk="select orderNumber, furnName, price, amount, sumPrice from OrdersItem where orderNumber=?;";
        List<OrderItem> list = new ArrayList<>();
        list = getSomeQuery(sqk, OrderItem.class,orderNumber);
        return list;
    }

    @Override
    public void updateStatue(String word,Integer userId,String orderNumber,String time) {
        String sql ="update Orders set statue = ?  where orderNumber=?";
        dml(sql,word,orderNumber);
    }
}
